from django.shortcuts import render
from django.http import HttpResponse
from app.models import UserInfo
from .models import ActicleList,ActicleType
import json
from myproject.responseMessage import responseType,jsonSerialize

# 保存文章
def addActicle(request): 
    userInfo = UserInfo()           
    acticleList = ActicleList()
    try :
        acticleList.user_id = UserInfo.objects.get(user_name=request.POST.get('user')).id
    except:
        return HttpResponse(json.dumps(responseType.error("用户不存在")))
    
    acticleList.acticleType_id = request.POST.get('acticleType')
    acticleList.name = request.POST.get('name')
    acticleList.content = request.POST.get('content')
    acticleList.save()
    return HttpResponse(json.dumps(responseType.success("恭喜你，发布成功等待审核",{})))

# 获取文章类型 所有
def acticleTypeList(request):
     try:
        dataAll = ActicleType.objects.all()
        return HttpResponse(json.dumps(responseType.success("",jsonSerialize.jsonData(dataAll))))
     except expression as identifier:
         return HttpResponse(json.dumps(responseType.error("文章类型获取失败")))

# 返回所有文章信息
def getActicleAll(request):
    try:
        
    except expression as identifier:
        return HttpResponse(json.dumps(responseType.error("文章获取失败")))
